<?php
set_time_limit(1800);
date_default_timezone_set('PRC');
require_once('config.php');

$now = time();
$ymd = date('Y-m-d', $now);
$day = date('N', $now);
$hour = date('H', $now);
$minute = date('i', $now);
$second = date('s', $now);
$week = date('D' , $now);

// linux 服务器上执行
//$phpcmd = exec("which php");

// 本地windows执行
$phpcmd = PHPCMD.'/php';
$dir = dirname(__file__);

// 每N分钟执行一次任务
if ($minute % 3  == 0)
{
    $total = 4; // 开4个进程
    for($i = 0; $i < $total; $i++)
    {
        $cmd = "$phpcmd '$dir/worker.php' 'check' $total $i >> $dir/cron_".date('Y-m-d').".log &";
        echo  date("Y-m-d H:i:s") . "\t : " .$cmd."\n";
        pclose(popen($cmd, 'r'));
        //system($cmd);
    }
}

// 定时处理任务
if (($hour == 6 or $hour == 15) and $minute  == 50)
{
    $cmd = "$phpcmd '$dir/worker.php' 'collect' >> $dir/cron_".date('Y-m-d').".log &";
        echo date("Y-m-d H:i:s") . "\t : " .$cmd."\n";
        //system($cmd);
        pclose(popen($cmd, 'r'));
}
?>
